home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Reading large files
- Date: Tue, 23 Jan 1996 15:10:31 +0200
- Organization: Carelcomp Forest
- Message-ID: <3104DE47.126F@cmt.lpr.mail.carel.fi>
- References: <310411A5.3438@cyber.cyb-live.com>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Alex Ibrado wrote:
- >
- > Hello! I have a friend who wants to read in a file of 1,000,000 doubles
- > into memory. (She's using Borland C++ 4.0/Windows.) The question is:
- > can it be done using a single fread? Since the algo requires reading in
- > the values several times (with a different offset each time), I
- > suggested using fseek instead of reading the whole file. However, with
- > 1,000,000 points read several times, this could be slow. sizeof(size_t)
- > returns 2; does this mean she could only read in 65535 doubles at a
- > given time?
- >
- > Would really appreciate any help you could extend. Thanks!
-
- Actually, this newsgroup is not necessarily the right one for this question
- (should try comp.os.msdos.programmer or comp.os.ms-windows.programming.misc,
- depending on which one your program is targeted to), but I'll give you a few
- hints. First, in 16-bit world (DOS, Win3x), size_t is normally a typedef for
- `unsigned int┤, which in fact is 0..65535. Thus: you can only read 65535
- _items_ at a time. However, your item might be something like ten doubles, so
- you'd end up reading 10*65535, ie. 655350 doubles at a time. Second, Intel
- machines in 16-bit mode use _segments_ of upto 65536 bytes, and a 16-bit read
- _cannot_ cross segment boundaries. When the offset within the segment grows
- past hex FFFF (ie. 65535 decimal), it wraps back to zero, and thus you'll end
- up overwriting the beginning of the segment.
-
- One way to read large amounts of data to one single array, is to use the huge
- memory model, in which your arrays can span multiple segments. You need to use
- a pointer (double huge *ptr) and huge alloc space for it. When you read the
- file, you must still do it in pieces that won't cross segment boundaries.
-
- This holds for Windows 3.x as well, because it too is a 16-bit product and
- uses segments (although there you'd rather use GlobalAlloc etc).
-
- HTH,
- AriL
-
- --
- All my opinions are mine and mine alone.
-